﻿using DemoApp.Model;
using DemoApp.Properties;
using DemoApp.ViewModel;
using MvvmFoundation.Wpf;

namespace DemoApp.CustomerModule.ViewModel
{
    public class CreateNewCustomerViewModel : CommandViewModel
    {
        private readonly ICustomerRepository _customerRepository;
        private readonly IMainWindowViewModel _mainWindowViewModel;

        public CreateNewCustomerViewModel(ICustomerRepository customerRepository,
                                          IMainWindowViewModel mainWindowViewModel)
            : base(Strings.MainWindowViewModel_Command_CreateNewCustomer)
        {
            _customerRepository = customerRepository;
            _mainWindowViewModel = mainWindowViewModel;

            Command = new RelayCommand(CreateNewCustomer);
        }

        private void CreateNewCustomer()
        {
            Customer newCustomer = Customer.CreateNewCustomer();
            var workspace = new CustomerViewModel(newCustomer, _customerRepository);
            _mainWindowViewModel.AddWorkspace(workspace);            
        }
    }
}